import java.util.Arrays;

public class ArrayMethod {
    public static void main(String[] args) {
        int[] arr1 = {23,33,12,45,20};
        int[] arr2 = {23,33,12,45,20};
        int[] arr3 = {23,60,38,11};
        //两个数组之间的比较Arrays.equals(arr1,arr2)
        System.out.println(Arrays.equals(arr1,arr2));
        System.out.println(Arrays.equals(arr1,arr3));
        //sort对数组进行升序排序
        Arrays.sort(arr1);
        System.out.println("\n升序结果为：");
        for(int arr:arr1){
            System.out.print(arr+"\t");
        }
        System.out.println("\n降序结果为：");
        for (int i=arr1.length-1;i>=0;i--){
            System.out.print(arr1[i]+"\t");
        }
        System.out.println("\n****************************");
        //toString();把一个数组转换成字符串
        System.out.println(Arrays.toString(arr1));
        System.out.println("\n****************************");
        //fill()：将数组进行赋值
        Arrays.fill(arr1,80);
        System.out.println(Arrays.toString(arr1));
        System.out.println("\n****************************");
        //copyOf()：把数组复制成一个新长度的数组
        int[] arr4 = Arrays.copyOf(arr2,4);
        int[] arr5 = Arrays.copyOf(arr2,7);
        System.out.println(Arrays.toString(arr4));
        System.out.println(Arrays.toString(arr5));
        //binarySearch();查找某个元素在数组中的位置（前提：数组已经进行升序排序）
        System.out.println("\n****************************");
        Arrays.sort(arr3);
        int index = Arrays.binarySearch(arr3,38);
        System.out.println("38在数组中的位置："+index);
        int index2 = Arrays.binarySearch(arr3,100);
        System.out.println("100在数组中的位置为："+index2);

        //字符串排序，并找出某个字符的位置
        char[] chars = {'a','v','f','b','q','x'};
        System.out.println("排序前："+Arrays.toString(chars));
        Arrays.sort(chars);
        System.out.println("排序后："+Arrays.toString(chars));

        int index3 = Arrays.binarySearch(chars,'x');

        System.out.println("x在数组中的位置为："+index3);

    }
}
